<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type="text/javascript" src="js/jsAddress.js"></script>
  <title>e网批发管理后台</title>
  <?php 
  include("common/conn.php");  
  include("./tool/UpFileTool.class.php");
  if($_GET['action']=="ok")
  {    
      if ($_FILES) {
        $UpFileTool=new UpFileTool('upfile');
        $UpFileTool->upImage();
        $images = $UpFileTool->sumbImage;
        $srcimages = $UpFileTool->srcImage;
      }

    $date = date("Y-m-d");
    $srat = mysql_query("INSERT INTO coupon(top_price,price,images,srcimages,title,number,enddate,jianjie,startdate,type,categroyids) VALUES ('$_POST[top_price]','$_POST[price]','$images','$srcimages','$_POST[title]','$_POST[number]','$_POST[enddate]','$_POST[jianjie]','$_POST[startdate]','$_POST[type]','".implode(",",$_POST[categroyids])."')");

    echo "<script>window.location.href='youhui.php';</script>";
}


  if($_GET['id']!=""){
    $rert37=mysql_query("select * from coupon where couponid='".$_GET['id']."'");
    $sdg37=mysql_fetch_array($rert37);
  }
    
if($_GET['ch']=="ok")
{
  if ($_FILES[upfile][tmp_name]!='') {
      $UpFileTool=new UpFileTool('upfile');
      $UpFileTool->upImage();
      $images = $UpFileTool->sumbImage;
      $srcimages = $UpFileTool->srcImage;
      $srat1=mysql_query("update coupon set images='".$images."',srcimages='".$srcimages."' where couponid='".$_REQUEST['id']."'");
    }

  $query = mysql_query("update coupon set type='".$_POST[type]."',categroyids='".implode(",",$_POST[categroyids])."',startdate='".$_POST[startdate]."',jianjie='".$_POST[jianjie]."',enddate='".$_POST[enddate]."',top_price='".$_POST[top_price]."',price='".$_POST[price]."',title='".$_POST[title]."',number='".$_POST[number]."' where couponid='".$_REQUEST['id']."'");

  echo "<script>window.location.href='youhui.php';</script>";
}


?>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/style2.css" rel="stylesheet" type="text/css" />  
<script type="text/JavaScript">
  <!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<script language="javascript" type="text/javascript" src="datepicker/WdatePicker.js"></script>
</head>

<body>

  <!-- header -->
  <?php include("common/header.php"); ?>
  <!-- header end -->
  <div id="sub_nav">

    <div id="subnav_wrap" class="container_12">

    </div>

  </div>
  <div class="container_12">
            <input type="button" class="submit" value="返回上一层" onclick="javascript:window.location.href='youhui.php?time='+new Date().getTime();">
          </div>
  <div class="container_12">
    <form action="?<?php if($_GET['id']!=""){echo "ch=ok";}else{echo "action=ok";} ?>"enctype="multipart/form-data" id="form" method="post">


      <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th width="20%" scope="col"><label>优惠券标题</label></th>
            <th width="80%" scope="col"><input name="title" class="text" type="text"  value="<?php echo $sdg37[title];?>"/></th>
          </tr>
          <tr>
            <th width="20%" scope="col"><label>优惠券说明</label></th>
            <th width="80%" scope="col"><textarea name="jianjie" class="text"  style="width: 350px;"><?php echo $sdg37[jianjie];?></textarea></th>
          </tr>
          <tr>
            <th width="20%" scope="col"><label>优惠券类型</label></th>
            <th width="80%" scope="col">
                  <select  name="type">
                       <option  <?php  if ($sdg37[type]==1) { ?> selected <?php } ?> value="1">新人专享优惠券</option>
                       <option  <?php  if ($sdg37[type]==2) { ?> selected <?php } ?> value="2">普通平台优惠券</option>
                  </select>
            </th>
          </tr>
          <tr>
            <th width="20%" scope="col"><label>适用范围</label></th>
            <th width="80%" scope="col">
                <input type="checkbox" name="categroyids[]" <?php if (strpos($sdg37['categroyids'], '0') || strpos($sdg37['categroyids'], '0') === 0) { ?> checked="checked" <?php } ?> value="0">全部分类
                  <?php 
                      $query = mysql_query("select * from categroy  order by cateid desc");
                      while ($row = mysql_fetch_assoc($query)) {
                      ?>
                        <input type="checkbox" name="categroyids[]" <?php if (strpos($sdg37['categroyids'], $row[cateid]) || strpos($sdg37['categroyids'], $row[cateid]) === 0) { ?> checked="checked" <?php } ?> value="<?php echo $row[cateid]; ?>">
                        <?php echo $row[name]; ?>
                  <?php } ?>
            </th>
          </tr>
          <!-- 满多少 -->
          <tr>
            <th width="20%" scope="col"><label>满多少</label></th>
            <th width="80%" scope="col"><input name="top_price" class="text" value="<?php echo $sdg37[top_price];?>"/></th>
          </tr>
          <!-- 满多少 end -->
          <!-- 送多少 -->
          <tr>
            <th width="20%" scope="col"><label>送多少</label></th>
            <th width="80%" scope="col"><input name="price" class="text" value="<?php echo $sdg37[price];?>"/></th>
          </tr>
          <!-- 送多少 -->
          <tr>
            <th width="20%" scope="col"><label>数量</label></th>
            <th width="80%" scope="col"><input name="number" class="text" value="<?php echo $sdg37[number];?>"/></th>
          </tr>
          <tr>
            <th width="20%" scope="col"><label>开始时间</label></th>
            <th width="80%" scope="col">
                <input name="startdate" type="text" value="<?php echo $sdg37[startdate];?>" style="cursor:pointer;" onClick="WdatePicker()"/>
            </th>
          </tr>
          <tr>
            <th width="20%" scope="col"><label>截止时间</label></th>
            <th width="80%" scope="col">
                <input name="enddate" type="text" value="<?php echo $sdg37[enddate];?>" style="cursor:pointer;" onClick="WdatePicker()"/>
            </th>
          </tr>
          <tr>
            <th width="20%" scope="col"><label>图标</label><span style="font-size: 8px;font-weight: normal;">(为了保持APP版面的协调性，请上传1:1比例图片)</span></th>
            <th width="80%" scope="col"><input name='upfile' class="text" type='file'/><img src="<?php echo $sdg37[images];?>"  height="auto" width="250"/></th>
          </tr>
          <input name="id" type="hidden" value="<?php echo $_GET[id];?>" />

        </table>
      </form>
    </div>

<div>    
  <input  type="submit" value="提交" id="submit"/>
</div>
</body>
<script type="text/javascript">
// 提交表单
  $('#submit').click(function(){
    $('#form').submit();
  })
// 提交表单 end
</script>
</html>
